from sqlalchemy import (
    Column,
    String,
    BigInteger,
    UUID,
    DateTime,
    PrimaryKeyConstraint,
    Index,
    text,
)

from internal.extension.extension_db import db
from sqlalchemy.dialects.postgresql import JSONB


class UploadFile(db.Model):
    """上传文件表模型"""
    __tablename__ = "upload_file"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pk_upload_file_id"),
        Index("idx_upload_file_account_id", "account_id")
    )

    id = Column(UUID, nullable=False, server_default=text('uuid_generate_v4()'))
    account_id = Column(UUID, nullable=False, index=True)
    name = Column(String(255), nullable=False, server_default=text("''::character varying"))
    key = Column(String(255), nullable=False, server_default=text("''::character varying"))
    size = Column(BigInteger, nullable=False)
    extension = Column(String(50), nullable=False, server_default=text("''::character varying"))
    mime_type = Column(String(100), nullable=False, server_default=text("''::character varying"))
    hash = Column(String(255), nullable=False, server_default=text("''::character varying"))
    updated_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'),
                        server_onupdate=text('CURRENT_TIMESTAMP(0)'))
    created_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'))
